package com.yvan.serverless.utils;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;

import java.io.IOException;

public class OracleTimestampToLongString extends ToStringSerializer {
    public final static OracleTimestampToLongString instance = new OracleTimestampToLongString();

    @Override
    public void serialize(Object value, JsonGenerator gen, SerializerProvider provider)
            throws IOException {
        if (value instanceof oracle.sql.TIMESTAMP) {
            try {
                gen.writeString(Long.toString(((oracle.sql.TIMESTAMP) value).timestampValue().getTime()));
            } catch (Exception e) {
                gen.writeString("");
            }
        } else {
            gen.writeString(value.toString());
        }
    }
}
